package com.itheima.controller;

import com.itheima.pojo.LoginInfo;
import com.itheima.pojo.LoginParam;
import com.itheima.pojo.Result;
import com.itheima.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginParam loginParam){

        LoginInfo loginInfo =  loginService.login(loginParam);

        return Result.success(loginInfo);

    }

    // @PostMapping("/login")
    // public Result login(@RequestBody LoginParam loginParam, HttpSession httpSession){
    //
    //    LoginInfo loginInfo =  loginService.login(loginParam);
    //
    //
    //
    //    if(loginInfo ==null){
    //        return Result.error("账号或者密码有误");
    //    }
    //
    //     httpSession.setAttribute("userInfo",loginInfo);
    //     return Result.success(loginInfo);
    //
    // }

}
